// mock测试
function createPlace (n) {
    var rad = Math.random();
    return {
            id:n+1, 
            longitude:120.24902-rad, latitude:30.215689+rad, 
            name: n + "aaa", 
            description: n + "description", 
            address: n + "address", 
            picture: ["https://ss1.bdstatic.com/lvoZeXSm1A5BphGlnYG/skin/36.jpg","https://ss1.bdstatic.com/lvoZeXSm1A5BphGlnYG/skin/36.jpg","https://ss1.bdstatic.com/lvoZeXSm1A5BphGlnYG/skin/36.jpg"]
        }
}
function createPlace2 (n) {
    var rad = Math.random();
    return {
            id:n+1, 
            longitude:120.24902-rad, latitude:30.215689+rad, 
            name: n + "dddddd", 
            description: n + "descriptionddddddddddddd", 
            address: n + "addressdddddddddddddd", 
            picture: ["","",""]
        }
}


function createList(n) {
    var result = [];
    for (var i = 0; i < n; i++) {
        result.push(createPlace(i));
    }
    return result;
}
function createList2(n) {
    var result = [];
    for (var i = 0; i < n; i++) {
        result.push(createPlace2(i+10));
    }
    return result;
}
var apiMap = {
	GET: {
		"/operating":{"code":"SUCCESS", "data":{
            list:[
                {"id":1,
                "topic":"好玩的活动",
                "description":"本次活动在西湖举行,扫二维码看详情",
                "imgUrl":"http://nos.netease.com/mini-findout-test/1.jpeg",
                "mlink":"http://www.baidu.com"
                },{"id":1,
                "topic":"好玩的活动2",
                "description":"本次活动在西湖举行,扫二维码看详情2",
                "imgUrl":"http://nos.netease.com/mini-findout-test/1.jpeg",
                "mlink":"http://www.baidu.com"
                },{"id":1,
                "topic":"好玩的活动3",
                "description":"本次活动在西湖举行,扫二维码看详情3",
                "imgUrl":"http://nos.netease.com/mini-findout-test/1.jpeg",
                "mlink":"http://www.baidu.com"
                }
        ]
        }},
		"/place/all": {"code":"SUCCESS", "data":{locations: {list:createList(10), pages: 10}}},
		"/place/page2": {"code":"SUCCESS", "data":{locations: {list:createList2(10), pages: 10}}},
        "/place/feature": {"code":"SUCCESS", "data":{locations: {list:createList(3), pages: 10}}},
        "/place/:id":{"code":"SUCCESS", "data":{
            "location":{
                "id":"1", 
                "longitude":"120.157696", 
                "latitude":"30.285087", 
                "name": "jch", 
                "typeId":"2",
                "description" : "sss",
                "rank":"dew",
                "activityId":"dd",
                "address": "hanghzoudwendmoeuowgbetget",
                "favorite":"", 
                "explorer":"", 
                "price":"",
                "picture":["http://nos.netease.com/mini-findout-test/1.jpeg","http://nos.netease.com/mini-findout-test/1.jpeg"],
            }
        }},
        "/place/nearby/info":  {"code":"SUCCESS", "data":{locations: {list:createList(5), pages: 10}}},
	},
	POST: {
		"/operating/add":{"code":"SUCCESS","msg":"OK"},
		"/login":{"code":"SUCCESS","data":{"token":"123456"}},
        '/place/feature':{"code":"SUCCESS","data":{}},
        '/place/picture/:id':{"code":"SUCCESS","msg":"OK"},
        '/place':{"code":"SUCCESS","msg":"added place success"}
	},
	DELETE:{},
	PUT:{
        "/place":{"code":"SUCCESS","msg":"OK"}
    }
};

function routeMap(){
	var str = {};
	Object.keys(apiMap).forEach(function(method){
		// var api = apiMap[method];
		Object.keys(apiMap[method]).forEach(function(url){
			var key = "" + method + " " + url;
			str[key] = function(req, res, next){
				res.send(apiMap[method][url]);
			}
		});
	});
	// console.log(str);
	return str;
}

module.exports = routeMap();